package com.zy.pay.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.zy.pay.api.ZyPayClient;
import com.zy.pay.api.ZyPayDefaultClient;
import com.zy.pay.api.request.ZyPayPreOrderRequest;
import com.zy.pay.api.response.ZyPayPreOrderResponse;

/**
 * demo控制器 <br>
 *
 * @author panweiqiang <br>
 * @date 2020/7/7 14:35 <br>
 */
@Controller
@RequestMapping(value = "/demo")
public class DemoController {

    /**
     * demo 入口
     * @return ModelAndView
     */
    @RequestMapping(value = "")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("/index");
        return modelAndView;
    }

    /**
     * 预下单
     * 
     * @param url 聚合支付网关地址
     * @param request ZyPayPreOrderRequest
     * @return ZyPayPreOrderResponse
     */
    @RequestMapping(value = "/preOrder")
    @ResponseBody
    public ZyPayPreOrderResponse preOrder(String url, String cpCode, String signKey, String appid, ZyPayPreOrderRequest request) {
        request.setProdName("下单测试商品");
        request.setTranType("测试");
        ZyPayClient zyPayClient = new ZyPayDefaultClient(url, cpCode, signKey, appid);
        return zyPayClient.execute(request);
    }
}